﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Green.ObjectPickUper
{
    /// <summary>
    /// 对象选择器
    /// </summary>
    public sealed class ObjectPickUperManager : IObjectPickUper
    {
        private IObjectPickUper _objectPickUper = new DefaultObjectPickUper();
        private static readonly ObjectPickUperManager _ObjectPickUperManager = new ObjectPickUperManager();

        /// <summary>
        /// 全局实例
        /// </summary>
        public static ObjectPickUperManager Instance
        {
            get
            {
                return _ObjectPickUperManager;
            }
        }
        /// <summary>
        /// 应用策略
        /// </summary>
        /// <param name="strategy"></param>
        public void ApplyPickUperStrategy(IObjectPickUper strategy)
        {
            if (strategy == null)
                throw new ArgumentException("strategy");
            this._objectPickUper = strategy;
        }

        #region IObjectPickUper 成员
        /// <summary>
        /// 根据Type提取对象
        /// </summary>
        /// <param name="pickedType">提取依据类</param>
        /// <param name="suffix">后缀</param>
        /// <returns></returns>
        public string PickUp(Type pickedType, string suffix)
        {
            return this._objectPickUper.PickUp(pickedType, suffix);
        }
        /// <summary>
        /// 根据Type提取对象
        /// </summary>
        /// <typeparam name="T">提取依据类</typeparam>
        /// <param name="suffix">后缀</param>
        /// <returns></returns>
        public string PickUp<T>(string suffix)
        {
            return this._objectPickUper.PickUp<T>(suffix);
        }
        /// <summary>
        /// 根据Type集合提取对象，加载后缀,返回 => (类型名称,代码)
        /// </summary>
        /// <param name="pickedType">提取依据类集合</param>
        /// <param name="suffix">后缀</后缀param>
        /// <returns>(类型名称,代码)</returns>
        public Dictionary<string, string> PickUp(IList<Type> pickedType, string suffix)
        {
            return this._objectPickUper.PickUp(pickedType, suffix);
        }
        /// <summary>
        /// 继承基类
        /// </summary>
        public Type BaseType
        {

            get { return this._objectPickUper.BaseType; }
            set { this._objectPickUper.BaseType = value; }
        }
        /// <summary>
        /// 是否实现INotifyPropertyChanged
        /// </summary>
        public bool IsImplementINotifyPropertyChanged
        {
            get { return this._objectPickUper.IsImplementINotifyPropertyChanged; }
            set { this._objectPickUper.IsImplementINotifyPropertyChanged = value; }
        }

        /// <summary>
        /// 是wcf对象？
        /// </summary>
        public bool IsSOAObject
        {
            get { return this._objectPickUper.IsSOAObject; }
            set { this._objectPickUper.IsSOAObject = value; }
        }

        #endregion
    }
}
